var arrImages = []; //保存图片数组
var index = 0;  //当前图片下标
var imgs = document.getElementById("imgs"); 

window.onload = getAllImages;   //初始化执行函数getAllImages

function getAllImages(){
    arrImages = imgs.getElementsByTagName("img");   //获取图片数组
    arrImages[index].style.display = 'block ';  //设置第一张图片显示
}

function pre(){     //上一张
    arrImages[index].style.display = 'none ';
    if(index === 0){
        index = arrImages.length;
    }
    arrImages[--index].style.display = 'block ';
}

function next(){    //下一张
    arrImages[index].style.display = 'none ';
    if(index === arrImages.length - 1){
        index = -1;
    }
    arrImages[++index].style.display = 'block ';
}

var timer = null;
function autoPlay () {
    timer = setInterval(function () {
        next();
    },1000);
}
autoPlay();

imgs.onmouseover = function(){
    clearInterval(timer);
}

imgs.onmouseout = autoPlay;